var DeviceSound = function(container,playerID,type) {
	this.container = container;
	this.playerID = playerID;
	this.applianceType = "";
	this.soundFile = "";
	switch (type)
	{
		/*case "fan":
			this.applianceType = 'fan';
			this.soundFile = "";
			break;
		case "washerdryer":
			this.applianceType = 'washerdryer';
			this.soundFile = "";
			break;*/
		case "vacuumcleaner":
			this.applianceType = 'vacuumcleaner';
			this.soundFile = "OGG/vacuumcleaner.ogg";
			break;
		case "dishwasher":
			this.applianceType = 'dishwasher';
			this.soundFile = "OGG/dishwasher.ogg";
			break;
		case "blowdryer":
			this.applianceType = 'blowdryer';
			this.soundFile = "OGG/blowdryer.ogg";
		default:
			break;
	}
	/*this.container.innerHTML = this.container.innerHTML + 
	'<audio id="'+this.playerID+'" type="audio/ogg" preload="auto" autobuffer loop>' +
		'<source src="'+this.soundFile+'"/></audio>';
	*/
	this.audioElt = document.createElement('audio');
	this.audioElt.setAttribute('id',this.playerID);
	this.audioElt.setAttribute('type','audio/ogg');
	this.audioElt.setAttribute('preload','auto');
	this.audioElt.setAttribute('autobuffer','true');
	this.audioElt.setAttribute('loop','true');
	var src = document.createElement('source');
	src.setAttribute('src',this.soundFile);
	this.audioElt.appendChild(src);
	this.container.appendChild(this.audioElt);
	
	//this.audioElt = document.getElementById(this.playerID);
	this.audioElt.addEventListener('ended', function(){ this.currentTime = 0; }, false);
	
	this.decrementVolume = function() {
		if (this.audioElt.volume > .5)
		{
			setTimeout(function(thisObj) { 
				thisObj.audioElt.volume = thisObj.audioElt.volume-.05;
				thisObj.decrementVolume();
			},40,this);
		}
	}
	
	this.turnOn = function() {
		this.audioElt.volume = 1;
		this.audioElt.play();
		setTimeout(function(thisObj) { thisObj.decrementVolume(); }, 5000, this);
	};
	
	this.turnOff = function() {
		this.audioElt.pause();
		this.audioElt.currentTime = 0;
	};
}


